/*
 * 有一个数在序列出现的次数超过一半，请找出此数
 *
 */

#include <stdio.h>

//计算第一个问题
int find_number_over_half(int * array, int num);

int find_number_over_half(int * array, int num)
{
    int count = 0, number = -1;
    for (int i = 0; i < num; ++i) {
        if (count == 0) {
            number = array[i];
            count++;
        }
        else if (number == array[i]) {
            count++;
        }
        else {
            count--;
        }
    }
    return number;
}

int main()
{
    int i[] = {10, 1, 10, 2, 3,
                4, 5, 10, 10, 2,
               10, 10, 10, 10, 9,
               10, 10, 10, 1, 2};
    printf("%d\n", find_number_over_half(i, 20));
}

